//引入axios，对其进行二次封装
import axios from "axios"
import nprogress from "nprogress"
import "nprogress/nprogress.css"
import store from "@/store"
const requests = axios.create({
    baseURL: "/api",
    timeout: 3000,
})
//请求拦截器 --- 在项目中发请求之前（请求没发出去）可以做一些事情
requests.interceptors.request.use((config) => {
    nprogress.start()
    if (store.state.detail.uuid_token) {
        config.headers.userTempId = store.state.detail.uuid_token
    }
    if (store.state.user.token) {
        config.headers.token = store.state.user.token
    }
    return config;
})
//响应拦截器 --- 服务器返回数据之后做一些事情
requests.interceptors.response.use((res) => {
    nprogress.done()
    return res;
}, (error) => {
    return Promise.reject(error)
})
export default requests;